﻿package app.view.components.buttons 
{
	import app.view.events.KeyboardEventD;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import gs.TweenLite;
	
	/**
	 * Базовый функционал кнопки клавиатуры
	 * @author Dmitryi_Koruagin, icq:585466579, dmitryikoruagin@mail.ru, skype: ok_ru1
	 */
	public class KeyBoardBtnD extends Sprite
	{
		//app.view.components.buttons.KeyBoardBtnD
		
		private var _keyID:int;
		private var _isBlock:Boolean=false;
		
		
		public function KeyBoardBtnD() 
		{
			init();
			this.alpha = 0;
		}
		
		private function init():void
		{
			
			
			isBlock = false;
		}
		
		private function setEvents():void
		{
			addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
			addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
		}
		
		private function removeEvents():void
		{
			removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
			removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
		}
		
		public function destroy():void
		{
			removeEvents();
		}
		
		
		private function onMouseDown(e:MouseEvent):void 
		{
			////trace('onMouseDown!!++',_keyID);
			this.alpha = 1;
			var ev:KeyboardEventD = new KeyboardEventD(KeyboardEventD.ON_KEY_DOWN);
			ev.id = _keyID;
			dispatchEvent(ev);
		}	
		
		public function onMouseUp(e:MouseEvent):void 
		{
			////trace('onMouseUp');
			TweenLite.to(this, 0.4, { alpha: 0 ,ease:'none'} );
		}
		
		public function get keyID():int { return _keyID; }
		
		public function set keyID(value:int):void 
		{
			_keyID = value;
		}
		
		public function get isBlock():Boolean { return _isBlock; }
		
		public function set isBlock(value:Boolean):void 
		{
			_isBlock = value;
			
			if (_isBlock == true ) 
			{
				removeEvents();
				onMouseUp(null);
			}else
			{
				setEvents();
			}
		}
	}

}